package com.cskaoyan.market.controller.Admin;

import com.cskaoyan.market.db.domain.MarketLog;
import com.cskaoyan.market.service.admin.MarketLogService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.List;

@RequestMapping("/admin/log")
@RestController
public class AdminLogController extends HttpServlet {
    @Autowired
    MarketLogService marketLogService;
    @GetMapping("list")
    public Object list(String page, String limit, String sort, String order, String name) throws IOException {

        Integer limitInt = null;
        Integer pageInt = null;
        try {
            limitInt = Integer.parseInt(limit);
            pageInt = Integer.parseInt(page);
        } catch (Exception e) {
            //直接返回一个响应结果
            System.out.println("e = " + e);
            return ResponseUtil.badArgument();
        }try {
            List<MarketLog> marketLogList = marketLogService.list(pageInt, limitInt, sort, order, name);
            return ResponseUtil.okList(marketLogList);
        }catch (Exception e) {
            return ResponseUtil.fail(500,"服务器内部错误");
        }
    }
}
